package com.azh.server.client;

import com.azh.server.transport.APackger;
import com.azh.server.transport.Package;
import com.azh.server.util.ExceptionUtils;

/**
 * @author zhaozhenhang <zhaozhenhang@kuaishou.com>
 * Created on 2022-05-02
 */
public class Client {

    private ATripper aTripper;

    public Client(APackger aPackger) {
        this.aTripper = new ATripper(aPackger);
    }

    public byte[] execute(byte[] stat) throws Exception {
        Package pkg = new Package(stat, null);
        Package resPkg = aTripper.roundTrip(pkg);
        if (resPkg.getErr() != null) {
            throw resPkg.getErr();
        }
        return resPkg.getData();
    }

    public void close() {
        try {
            aTripper.close();
        } catch (Exception e) {
            ExceptionUtils.getMessage(e);
        }
    }
}
